// @author: caoshi
// @date: 2021-06-06 20:34
package v1

import (
	"demo08_paramsbind/src/model"
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

// /blogs/find
func QueryBlogs(c *gin.Context) {
	//id := c.Query("id")
	//fmt.Println("查询博客!, 参数id = ", id)
	// c.String(http.StatusOK, "query success ..")
	users := make([]model.User, 3)
	users = append(users, model.User{
		Username: "zhangsan",
		Password: "123123",
	})

	users = append(users, model.User{
		Username: "lisi",
		Password: "111",
	})

	blog := model.Blog{
		Id:        "1001",
		Title:     "golang 反射技术",
		Content:   "golang reflect 技术是非常牛b的, 哈哈哈",
		Labels:    []string{"reflect", "golang", "java"},
		StartUser: users,
	}
	//c.String(http.StatusOK, "success", blog)
	c.JSON(http.StatusOK, gin.H{
		"blog": blog,
	})
}

/**
SaveBlogs
{
    "id": "alfhalfkhafklaefhasfaf",
    "title": "GoLang Study",
    "content": "golang is a very good language",
    "labels": [
        "go",
        "java",
        "test"
    ],
    "startUser": [
        {
            "username": "zhangsan",
            "password": "123123"
        },
        {
            "username": "lisi",
            "password": "111111"
        }
    ]
}
*/
func SaveBlogs(c *gin.Context) {
	var blog model.Blog
	err := c.ShouldBindJSON(&blog)
	if err != nil {
		fmt.Println("出错")
	}
	fmt.Println(blog)
	c.JSON(http.StatusOK, blog)
}

func DeleteBlogs(c *gin.Context) {
	fmt.Println("删除博客")
}
